package com.solidumgame.martillo.health
{
	import com.pblabs.engine.PBE;
	import com.pblabs.engine.entity.PropertyReference;
	import com.pblabs.rendering2D.MovieClipRenderer;
	import com.solidumgame.martillo.health.events.HealthGenericEvent;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class HealthRendererComponent extends MovieClipRenderer
	{	
		//public var houseImage:MovieClip;
		protected var houseHealth:HouseHealth;
		
		public function HealthRendererComponent()
		{
			super();
			
			houseHealth = new HouseHealth();
			
			this.size = new Point(50,73);
			this.position = new Point(-250,-150);
			this.clip = houseHealth; 
			this.scene = PBE.scene;
			this.layerIndex = 100;
		
		}
		
		override protected function onReset():void
		{
			super.onReset();
			owner.eventDispatcher.addEventListener(HealthGenericEvent.DAMAGE_EVENT,updateHouseImage);
			owner.eventDispatcher.addEventListener(HealthGenericEvent.UP_HEALTH_EVENT,updateHouseImage);
		}
		
		override protected function onRemove():void
		{
			super.onRemove();
			owner.eventDispatcher.removeEventListener(HealthGenericEvent.DAMAGE_EVENT,updateHouseImage);
			owner.eventDispatcher.removeEventListener(HealthGenericEvent.UP_HEALTH_EVENT,updateHouseImage);
		}
		
		protected function updateHouseImage(e:HealthGenericEvent):void
		{			
			houseHealth.setHealth(e.health);

		}
	}
}